@{
    ViewBag.Title = "URL编码/解码、编码解码";
    ViewBag.keywords = "URL编码,URL解码,encodeURI,encodeURIComponent";
    ViewBag.description = "在线URL编码、解码工具,URL解码,encodeURI,encodeURIComponent";
}
<div class="layui-row layui-form layui-form-pane">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容：</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" id="content" name="content" rows="8" onpaste="setTimeout(encode,1)" lay-verify="required" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <a class="layui-btn" onclick="encode();">编码</a>
        <a class="layui-btn layui-btn-normal" onclick="decode();">解码</a>
        <a class="layui-btn layui-btn-warm" onclick="icdecode();">IC解码</a>
        <a class="layui-btn layui-btn-danger" onclick="cleanup();">清空</a>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">encodeURI：</label>
        <div class="layui-input-block">
            <textarea placeholder="输出encodeURI" id="outContent" name="outContent" rows="8" onpaste="setTimeout(decode,1)" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">Component：</label>
        <div class="layui-input-block">
            <textarea placeholder="输出encodeURIComponent" id="area_encoded_component" name="area_encoded_component" rows="8" onpaste="setTimeout(decode,1)" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <blockquote class="layui-elem-quote">
        encodeURI()是Javascript中用来对URL编码的函数。它着眼于对整个URL进行编码，因此除了常见的符号以外，对其他一些在网址中有特殊含义的符号<strong> "; / ? : @@ &amp;= + $ , #"</strong> ，也不进行编码。编码后，它输出符号的utf-8形式，并且在每个字节前加上%。
    </blockquote>
    <blockquote class="layui-elem-quote">
        encodeURIComponent()与encodeURI()的区别是，它用于对URL的组成部分进行个别编码，而不用于对整个URL进行编码。因此<strong>"; / ? : @@ &amp; = + $, #"</strong>，这些在encodeURI()中不被编码的符号，在encodeURIComponent()中统统会被编码。至于具体的编码方法，两者是一样。
    </blockquote>
</div>
@section Scripts{
<script>
    let area_url = document.getElementById('content');
    let area_encoded = document.getElementById('outContent');
    let area_encoded_component = document.getElementById('area_encoded_component');

    function encode() {
        area_encoded.value = encodeURI(area_url.value);
        area_encoded_component.value = encodeURIComponent(area_url.value)
    }
    function decode() {
        area_encoded.value = decodeURI(area_url.value)
    }
    function icdecode() {
        area_encoded_component.value = decodeURIComponent(area_url.value)
    }
    function cleanup() { area_url.value = ''; area_encoded.value = ''; area_encoded_component.value = ''; }
</script>
}

